<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<sfa:mainTitle></sfa:mainTitle>
<%@ include file="/common/meta.jsp"%>
<style type="text/css">
.title { 
	display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 125px; } 
</style>
<script type="text/javascript">
	 

$(function() {
//fixTable.FixTable("mytable");
	$("#fullScreen").click(function() {
		fullScreen.FullScreen("mytable");
	});
})
</script>
		<script type="text/javascript">
$(function() {
$("input[name='roles']:checked").click(function(){
   
  	$(this).removeAttr("checked");
   
});
	
	//全选
	$("#all").click(function(){
		$("input[name='roles']").attr("checked","checked");
	});
	
	//全不选
	$("#allNot").click(function(){
		$("input[name='roles']").removeAttr("checked");
	});
	
	//反选
	$("#reverse").click(function(){
		var checkeds=new Array();
		$("input[name='roles']:checked").each(function(){
			var value=$(this).attr("id");
			checkeds.push(value);		
		});
		
		
		
		var checkeds1=new Array();
		$("input[name='roles']:not(input[name='roles']:checked)").each(function(){
			var value=$(this).attr("id");
			checkeds1.push(value);		
		});
		
		for(var i=0;i<checkeds.length;i++)
		{
			var id=checkeds[i];
		    $("input[id='"+id+"']").removeAttr("checked");	
		}
		for(var i=0;i<checkeds1.length;i++)
		{
			var id=checkeds1[i];
		    $("input[id='"+id+"']").attr("checked","checked");	
		}
		//$("input[name='roles']:not(input[name='roles']:checked)").attr("checked","checked");
	});
	//提交
	$("#submit").click(function(){
		 
		 
	var url="${path}/manage/role/index/manageUserRole";
		 
		var role=$("input[name='roles']:checked");
		
		var roles="";

		if(role!=null)
		{
			for(var i=0;i<role.length;i++)
			{
				roles=(roles+role.get(i).value)+(((i+1)==role.length)?'':',');
			}
		}
		var userid="${user.saleUsersLoginId}";
		var param={"userId":userid, 
		"roleId":roles};
		
		art.dialog( {
				lock : true,
				content : '确定要绑定吗?',
				ok : function() {
					art.dialog( {
						id : "loading",
						lock : true,
						drag : false,
						resize : false,
						title : "正在绑定...",
						time : 5
					});
					$.post(url, param, function(result) {
						art.dialog( {
							id : 'loading'
						}).close();//关闭等待框
							if (result.result) {
								art.dialog( {
									icon : "succeed",
									content : result.msg,
									lock : true,
									ok : function() {
										location.href='${path}/manage/role/index/getAllUsers';
									}
								});
							} else {
								art.dialog( {
									icon : "error",
									content : result.msg,
									lock : true,
									ok : true
								});
							}

						});

					return true;
				},
				cancelVal : '关闭',
				cancel : true
			//为true等价于function(){}
					});
		  
	});
	//分析所有角色进行数据回显
	var myrole='${myrole}';
	myrole=myrole.substring(1,myrole.length-1);
	myrole=myrole.split(",");
	//alert(branchids.length);
	  var boxObj = $("input[name='roles']");  //获取所有的复选框 
     var index = 0;
     for(i=0;i<boxObj.length;i++){
        for(j=0;j<myrole.length;j++){            
            if(boxObj[i].value == myrole[j].replace(/^\s+|\s+$/g,""))  //如果值与修改前的值相等
            {
                boxObj[i].checked= true;
                break;
            }
        }
     }   

});
</script>

	</head>

	<body id="master">

		<sfa:mainHeader></sfa:mainHeader>
		<!--右边-->
            <div class="webpart3 contentarea">
                <div class="webpart-head">
                    <div class="webpart-head-item">
                       绑定用户角色
                        <div class="tools-btn">
                             &nbsp;&nbsp;<a href="javascript:" onclick="javascript: history.back();"><span>
                                <img src="${path}/statics/images/Redo.gif" style="margin-right: 4px; margin-bottom: -3px;" />返回</span></a>
                            
                                 </div>
                    </div>
                </div>
                <div class="webpart-main">
                    <div class="webpart-main-item" style="padding-top: 12px;">
                        <div class="search">
                            <!----------- 查询信息 ------------------>
                            
                            <table cellpadding="0" cellspacing="0">
                                <tr>
                                    <td>
                                       用户姓名:${user.userName}
                                    </td>
                                     
                                </tr>
                                <tr>
                                	 
                                     
                                </tr>
                                <tr>
                            	<td colspan="3">
                            		
                            		
                            		<input type="button" id="all" name="all" value="全选" class="linkbtn2">
                            		<input type="button" id="allNot" name="allNot" value="全不选" class="linkbtn2">
                            		<input type="button" id="reverse" name="reverse" value="反选" class="linkbtn2">
                            		<input type="button" id="submit" name="submit" value="绑定" class="linkbtn2">
                            	</td>
                            </tr>
                            </table>
                            
                        </div>
                        <!----------- 数据列表 ------------------>
                        <form method="post" name="form1" id="form1" style="height: 300px;overflow: auto;">
                        <table cellpadding="0" cellspacing="0" class="dg_borderstyle trStyleTable" style="margin-top: 15px;line-height: 23px;" id="mytable">
                            
                            
                            <tr>
                            	<th >
								序号
							</th>
                                <th >
                                  角色名
                                </th>
                                <th >
                                  基本角色
                                </th>
                                <th >
                                  角色状态
                                </th>
                                <th>
                                    角色描述
                                </th>
                                
                            </tr>
                            <c:forEach items="${roles}" var="role" varStatus="ind">
                            <tr  >
                            <td>${ind.index+1}</td> 
                                <td width="30%" align="left" >
                                <div style="width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
									<input type="checkbox" name="roles" id="role${ind.index+1}" value="${role.saleRoleId}"/>
									
									<label for="role${ind.index+1}">${role.roleName}</label>
									</div>
								</td>
								<td align="center">
									${role.isBaseRole=='1'?'是':'否'}
								</td>
								<td align="center">
									${role.roleStatus=='1'?'启用':'禁用'}
								</td>
								<td align="center">
									${role.roleContent }
									 
								</td>
								 
                            </tr>
                            </c:forEach>
                            
                        </table>
                        </form>
                         
                
            </div>
            </div>
            <div class="webpart-foot">
                    <div class="webpart-foot-item">
                    </div>
                </div>
            </div>

		<sfa:mainFooter></sfa:mainFooter>

	</body>
</html>


